
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="root"></div>
    
</body>
<script>


// 动态组件：根据数据的变化，结合component这个标签，来随时动态切换组件的显示
    const app = Vue.createApp({
        components: {
        },
        data(){
            return {
              currentItem: "input-item"
            }
        },
        methods:{
            handleClick(){
                return this.currentItem = this.currentItem==='input-item'?'common-item':'input-item';
            }
        },
        template:
        // `
        //    <input-item v-if="currentItem==='input-item'"/>
        //    <common-item v-if="currentItem==='common-item'"/>
        //    <button @click="handleClick">切换</button>
        // `
        `
           <keep-alive>
                <component :is="currentItem"/>
            </keep-alive>
           <button @click="handleClick">切换</button>
        `
    });

    app.component('input-item', {
        props: {
            
        },
        methods: {
           
        },
        template: 
        `
            <input/>
        `
    });

    app.component('common-item', {
        props: {
            
        },
        methods: {
           
        },
        template: 
        `
            <div> hello wrold </div>   
        `
    });

    const vm = app.mount("#root");
</script>
</html>